<template>
	<view class="login-box">
		<view>
			<view class="min-bg">
				<image :src="login_bg" mode=""></image>
			</view>
			<view class="login-form" >
					<view>					
						<view class="mobile-tit">{{brand}}家长助手-登陆</view>
						<view class="txts">
							<input type="number" :value="formData.mobile" @blur="getText" placeholder="请输入手机号" class="phone">
						</view>
						<view class="txts code">
							<input type="password" :value="formData.password" @blur="getText2" placeholder="请输入密码" class="txt-code" style="width: 500rpx;">
						  <!-- <text>获取验证码</text> -->
						</view>

						<view class="sub_login" @click="mobile_bind">登录</view>
						<!-- <view class="regist" @tap="showRegister">账号注册></view> -->
					</view>
			</view>
		 </view>
		<view class="copyright-login" >
			<copyRight></copyRight>
		</view>
	</view>
</template>

<script>
	import copyRight from '../../components/copyright.vue';
	export default {
		components : {
			copyRight 
		},
		data() {
			return {
				userInfo : {
				},
				formData : {
					// mobile : '18000712888',
					// password:'712888',
					mobile : '13766599999',
					password:'599999',
					// mobile : '18870810230',
					// password:'810230',
					// mobile : '18056095789',
					// password:'095789',
					// mobile : '18170019589',
					// password:'019589',
					// mobile : '15176576838',
					// password:'576838',
					// mobile : '17625494810',
					// password:'494810',
					// mobile : '13870932831',
					// password:'932831',
					// mobile : '13870818448',
					// password:'818448',
					// mobile : '13517009055',//绕自信
					// password:'009055',
					// mobile : '18070039878',
					// password:'039878'
				},
				open_id:'',
				targetPage :'',
				login_bg:this.config.DEFAULT_LOGIN_BG,
				brand:this.config.DEFAULT_BRAND
			}
		},
		onLoad(option) {
			if(option.mobile){
				this.formData.mobile = option.mobile
				this.formData.password = option.mobile.substring(5,11)
			}
			this.mobile_bind()
		},
		onShow() {
		},
		methods:{
			getText(e){
				this.formData.mobile = e.detail.value
			},
			getText2(e){
				console.log('xx',e.detail.value)
				this.formData.password = e.detail.value
			},
			mobile_bind () {
				if (this.formData.mobile.length != 11 ){
					uni.showToast({
						icon:'none',
						title: '手机号不正确'
					});
				}
				if (this.formData.password.length < 6){
					uni.showToast({
						icon: 'none',
						title: '密码最少长度为6位'
					});
				}
				uni.showLoading({
					title:'登陆中...'
				})
				let that = this
				
				this.common.http.request('/api/v1/auth/login','POST',{
					account_name : this.formData.mobile,
					password : this.formData.password,
					app_id:this.config.APP_ID
				}, res => {
					if (res.data.code == 0) {
						getApp().globalData.userInfo = {account:res.data.data,open_id:that.open_id};
						getApp().globalData.currentCustomer = res.data.data.customers[0];
						getApp().globalData.access_token = res.data.data['access-token'];
						getApp().globalData.isSuper = 1;
						if(that.targetPage){
							// uni.navigateTo({
							// 	url:'../index/sign-in/sign-in-visiter'
							// })
							uni.redirectTo({
								url:'../index/sign-in/sign-in-visiter'
							})
						} else {
							uni.reLaunch({
								url:'../index/index'
							})
						}
					} else {
						uni.showToast({
							icon:'none',
							title:res.data.message
						})
					}
				},false)


			},
			showRegister() {
				uni.navigateTo({
					url:'../regist/regist'
				})
			},
			
		},
	}
</script>

<style lang="scss" scoped>
	.login-phone{
		font-size:48rpx;
		font-family:PingFangSC-Semibold,PingFang SC;
		font-weight:600;
		color:rgba(51,51,51,1);
		letter-spacing:1rpx;
	}
	.phone{
		margin-top: 56rpx;
		padding: 0 20rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		height:90rpx;
		background:rgba(255,255,255,1);
		border-bottom:1rpx solid #efefef;
		font-size:24rpx;
		font-family:PingFangSC-Medium,PingFang SC;
		font-weight:500;
		color:rgba(102,102,102,1);
	}
	.code{
		font-size:32rpx;
		font-family:PingFangSC-Semibold,PingFang SC;
		font-weight:600;
		color:rgba(182,29,36,1);
	}
	.button{
		background:rgba(182,29,36,1);
		width:417rpx;
		height:98rpx;
		margin: 0 auto;
		margin-top: 50rpx;
		border-radius:43rpx;
		text-align: center;
		line-height: 98rpx;
		border:1rpx solid rgba(151,151,151,1);
		color: #fff;
	}
	.regist{
		font-size:32rpx;
		font-family:PingFangSC-Semibold,PingFang SC;
		font-weight:600;
		color:rgba(215,58,70,1);
		margin: 0 auto;
		margin-top: 42rpx;
		text-align: center;
		
	}
	.login-box {
		height: 100%;
		// position: relative;
		.min-bg{
			width:100%;
			height:678rpx;
			background-size: 100%;
			image{
				width:100%;
				height:678rpx;
			}
		}
		.login-form{
			width:86%;
			position: absolute;
			left:7%; top:30%;
			background:#fff;
			box-shadow: 0 5rpx 5rpx 5rpx #eee;
			border-radius:8rpx;
			padding: 6% 4%;

			.mobile-tit{
				font-size:48rpx;
				color:#333;
				margin-bottom:20rpx;
				font-weight:600;
			}
			.txts{
				border-bottom:1px solid #ddd;
				margin-bottom:54rpx;
				.phone{
					height:80rpx;
					line-height:80rpx;
					font-size:30rpx;
					color:#666;
				}
				.txt-code{
					height:80rpx;
					padding: 0 20rpx;
					line-height:80rpx;
					font-size:30rpx;
					color:#666;
				}
			}
			.code{
				height:80rpx;
				line-height:80rpx;
				display:flex;
				justify-content: space-between;
				text{
					font-size:32rpx;
					color:#B61D24;
				}
			}
			.sub_login{
				width:417rpx;
				height:100rpx;
				line-height: 100rpx;
				background:linear-gradient(301deg,rgba(220,62,74,1) 0%,rgba(182,29,36,1) 100%);
				border-radius:81rpx;
				text-align: center;
				color:#fff;
				font-size:30rpx;
				margin: 80rpx auto 40rpx;
			}
		}
	}

</style>
<style lang="scss" scoped>
    .header {
        margin: 90rpx 0 90rpx 50rpx;
        border-bottom: 1px solid #ccc;
        text-align: center;
        width: 650rpx;
        height: 300rpx;
        line-height: 450rpx;
    }

    .header image {
        width: 200rpx;
        height: 200rpx;
    }

    .content {
        margin-left: 50rpx;
        margin-bottom: 90rpx;
    }

    .content text {
        display: block;
        color: #9d9d9d;
        margin-top: 40rpx;
    }

    .bottom {
        border-radius: 80rpx;
        margin: 70rpx 50rpx;
        font-size: 35rpx;
    }
	.copyright-login{
		width:100%;
		position: fixed;
		top: 93%;
	}
</style>
